package booksystem.controller;

import booksystem.dao.BookDao;
import booksystem.dao.impl.BookDaoImpl;
import booksystem.entity.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name="IndexServlet", urlPatterns = {""})
public class IndexServlet extends HttpServlet {
    private BookDao bookDao = new BookDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取全部图书信息
        List<Book> allBook = bookDao.getAllBook();

        // 设置application对象属性
        req.setAttribute("bookList", allBook);
//        resp.sendRedirect("/index.jsp");
        req.getRequestDispatcher("/index.jsp").forward(req, resp);
    }
}
